
import urlConfig from './config.js'

const request = {}
const headers = {}
/*
 *url:接口地址
 * method:请求方式
 * data:参数
 * power:1 formdata传参 2.url传参
 */
request.globalRequest = (url, method, data, power) => {
	/*
	 *
	 * 1 :application/json 2:application/x-www-form-urlencoded
	 */
	switch (power) {
		case 1:
			headers['content-type'] = 'application/json';
			break;
		case 2:
			headers['content-type'] = 'application/x-www-form-urlencoded';
			break;
		default:
			headers['content-type'] = 'text/plain';
			break;
	}
	/**
	 * 权限判断 因为有的接口请求头可能需要添加的参数不一样，所以在这里做了区分
	 * 1==不通过access_token校验的接口
	 * 2==文件下载接口列表
	 * 3==验证码登录
	 */
	// switch (power) {
	// 	case 1:
	// 		headers['Authorization'] = 'Basic a3N1ZGk6a3N1ZGk='
	// 		break;
	// 	case 2:
	// 		headers['Authorization'] = 'Basic a3N1ZGlfcGM6a3N1ZGlfcGM='
	// 		break;
	// 	case 3:
	// 		responseType = 'blob'
	// 		break;
	// 	default:
	// 		// headers['Authorization'] = `Bearer ${
	// 		//                this.$store.getters.userInfo
	// 		//            }`
	// 		// headers['TENANT-ID'] = this.$store.getters.userInfo.tenant_id
	// 		break;
	// }

	return uni.request({
		url: urlConfig + url,
		method,
		data: data,
		dataType: 'json',
		header: headers
	});
}


request.globalRequestFile = (url, method, data, power) => {
	switch (power) {
		case 1:
			headers['content-type'] = 'application/json';
			break;
		case 2:
			headers['content-type'] = 'application/x-www-form-urlencoded';
			break;
		default:
			headers['content-type'] = 'text/plain';
			break;
	}

	return uni.request({
		url: "http://192.168.199.203:8030" + url,
		method,
		data: data,
		dataType: 'json',
		header: headers
	});
}
export default request
